package tyk.Service;

import tyk.Dao.BaseDao;
import tyk.pojo.User;

import java.awt.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/***
 *@title UserRegisterService
 *@description <TODO description class purpose>
 *@author Tang'ya'kang
 *@VERSION 1.0.0
 *@CREATE 2023/5/5 21:29
 **/
public class UserService extends BaseDao {
    private String username;
    private String password;
    private String email;

public UserService() {
}

public UserService(String username, String password, String email) {
    this.username = username;
    this.password = password;
    this.email = email;
}

public void setPassword(String password) {
    this.password = password;
}

public String getPassword() {
    return password;
}

public int Register(){
    int rows=0;
    String sql="insert into user (username,password,email) values (?,?,?);";
try {
    rows = super.executeUpdate(sql,username,password,email);
} catch (SQLException throwables) {
    throwables.printStackTrace();
}
return rows;
}

public List Login(){
    List<User> list=new ArrayList<>();
    String sql="select username,password,email,id from user where username = ? and password = ? ;";
try {
    list = super.executeQuery(User.class,sql,username,password);
} catch (SQLException throwables) {
    throwables.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (InstantiationException e) {
    e.printStackTrace();
} catch (NoSuchFieldException e) {
    e.printStackTrace();
}
return list;
}

}
